// pages/device/use/index.js
var app = getApp(), fetchApi = require("../../../utils/httpPost.js"), common_Js = require("../../../component/common.js")
import Dialog from '../../../component/vant/dialog/dialog';
import Toast from '../../../component/vant/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isLoading: true, 
        loading: false, 
        netWork: false,
        submitState:false,
        record_id:0,
        record:{},
        wd:0,
        jd:0,
        check_result:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('use  options',options)
        if(options.id){
            this.data.record_id = parseInt(options.id);
        }
        this.onHttpInit();
    },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    console.log('onHttpInit')
    var that = this;
    fetchApi.httpPost('/device/welding/record/detail', {
      record_id:that.data.record_id,
    }, function (res) {
      console.log("传感器设备上报记录响应数据", res)
      if (res.data.code == 0) {
        that.setData({
            record: res.data.data.record
        })
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
  },
  bindInput(e){
    this.data.check_result = e.detail || "";
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpSubmit: function (e) {
      var state = e.currentTarget.dataset.state;
    var that = this;
    fetchApi.httpPost('/device/welding/manager/check', {
      record_id:that.data.record_id,
      check_state: state,
      check_result: that.data.check_result,
    }, function (res) {
      console.log("审核会申请响应数据", res)
      if (res.data.code == 0) {
          Toast.success(res.data.msg);
          setTimeout(function(){
            wx.navigateBack({
                delta:-1
            })
          },800)
      }else{
        Toast.fail(res.data.msg);
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
  },
})